package com.dao.impl;

import java.util.List;

import com.dao.RoleDao;

public class RoleDaoImpl extends UniversalDaoImpl implements RoleDao {

	@Override
	public List getListTree(String code) {
		String sql;
		if (code == null||"".equals(code))
			sql = "select code id,'['+code+'] '+name text,isLeaf leaf from role where  (parent_code is null or parent_code='') and enabled=1 order by code";
		else
			sql = "select code id,'['+code+'] '+name text,isLeaf leaf from role where  parent_code='"
					+ code + "' and enabled=1 order by code";
		logger.info(sql);
		return queryForList(sql);
	}

	@Override
	public void saveRoleMenuTree(String roleCode, String menuCodes) {
		String sql;
		sql="delete role_menu where role_code='"+roleCode+"' and menu_code in("+menuCodes+")\n";
		sql += "insert role_menu(role_code,menu_code) select '"+roleCode+"',code from menu where code in ("+menuCodes+")";
		logger.info(sql);
		this.execute(sql);
	}

}
